package com.xiaobai.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.stereotype.Component;

/**
 * @author yangdaji
 * @version 1.0
 * @Description: 令牌存储策略
 * @date 22-2-20 下午 11:14
 */
@Component
public class JwtTokenStoreConfig {

    /**
     * jwttoken转换器
     */
    @Autowired
    private JwtAccessTokenConverter jwtAccessTokenConverter;

    /**
     * 因为配置了redis存储,暂时不使用
     *
     * @return
     */
    @Primary
    @Bean
    public TokenStore jwtTokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter);
    }

    @Bean
    public JwtAccessTokenConverter getTokenAccess() {
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        //配置jwt的密钥
        jwtAccessTokenConverter.setSigningKey("test_key");
        return jwtAccessTokenConverter;
    }

    /**
     * jwttoken增强器
     *
     * @return
     */
    @Bean
    public JwtTokenEnhancer getTokenEnhancer() {
        return new JwtTokenEnhancer();
    }
}
